<?php
Globals::requireClass('Controller');
Globals::requireModel('User');
Globals::requireTable('Title');

class TitleController extends Controller
{
	protected $TitleTable;
	
	public static $defaultConfig = array(
		'viewEnabled'	=> true,
		'layoutEnabled'	=> true,
		'title'			=> null
	);
	
	public function __construct($config = null)
	{
		parent::__construct($config);
		$this->TitleTable = new TitleTable($config);
		dolog(json_encode($_GET));
	}
	
	public function indexAction()
	{
		$this->layout->pageTitle	= "test";
	}
	
	//头条信息，广告
	public function headlineAction(){
	    $uid = $this->getParam('uid');
	    $token = $this->getParam('token');
	    $machine_type = $this->getParam('machine_type');
	    $usermodel = new UserModel($this->config);
	    $uid = $usermodel->getUserBase($uid, $token ,$machine_type);
	    if($uid < 1){
	        echo json_encode(array('returncode'=>'-1','list'=>array()));
	        exit();
	    }
	    
	    $list = array();
	    $data = $this->TitleTable->listAll(array('is_hidden'=>0),'rank ASC');
	    foreach ($data as $v){
	        $tmp = array();
	        $tmp['describe'] = $v['remark'];
	        $tmp['url'] = $v['url'];
	        
	        $list[] = $tmp;
	    }
	    
	    echo json_encode(array('returncode'=>'0','list'=>$list));
	    exit();
	}
	
	protected function out()
	{
		$this->layout->nav		= 'index';
		parent::out();
	}
}

Config::extend('TitleController', 'Controller');
